#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 2e5 + 10;

int n, q;
int a[N];
bool st[N];
int h[N], e[N * 4], ne[N * 4], w[N * 4], idx;

void add(int a, int b, int c){
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx ++;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;
    for(int i = 1; i <= n; i ++) a[i] = (1 << 30) - 1;
    for(int i = 1; i <= n; i ++) h[i] = -1;

    int opi, opj, opx;
    while(q --){
        cin >> opi >> opj >> opx;
        if(opi == opj){
            a[opi] = opx;
            st[opi] = true;
            continue;
        }

        add(opi, opj, opx);
        add(opj, opi, opx);
        for(int i = 0; i < 30; i ++){
            if(((opx >> i) & 1) == 0){
                if((a[opi] >> i) & 1) a[opi] ^= (1 << i);
                if((a[opj] >> i) & 1) a[opj] ^= (1 << i);
            }
        }
    }

    for(int i = 29; i >= 0; i --){
        for(int j = 1; j <= n; j ++){
            if(st[j]) continue;
            if(((a[j] >> i) & 1) == 0) continue;

            bool flag = true;

            for(int p = h[j]; p != -1; p = ne[p]){
                int k = e[p], num = w[p];

                if(((w[p] >> i) & 1) == 0) continue;

                if(((a[k] >> i) & 1) == 0){
                    flag = false;
                    break;
                }
            }

           if(flag){
                a[j] ^= (1 << i);
            }

        }
    }

    for(int i = 1; i <= n; i ++){
        cout << a[i] << " ";
    }

    cout << '\n';



    return 0;
}